/**
 * @file {pantie目标库flaw表model}
 */
 'use strict'

 const { DataTypes, Model, Op } = require('../../../azeroth').sequelize;
 const {flawInitData} = require('../common/init_data');
 class FlawMujian extends Model { }
 
 /**
  * @desc 映射需要的字段 【源库的 部分字段 --> 目标库字段】
  */
  const initFlawMujinaData = (sequelize_aim) => {
    FlawMujian.init(
        ...flawInitData,
        {
            freezeTableName: true,
            sequelize: sequelize_aim,
            modelName: 'flaw',
            timestamps: false
        }
     )
  }
  /**
   * 获取汇总库flaw表的Uid的最大值
   * @param {}} sequelize_aim 
   */
  FlawMujian.getMaxUidfromDb = async (sequelize_aim) => {
    let sql = "select max(uid) as uid from flaw";
    let res = await sequelize_aim.query(sql, { type: sequelize_aim.QueryTypes.SELECT });
    return res[0].uid ? res[0].uid : 0;
  }
  /**
   * 上传flaw信息
   * @param {Array} data 上传的缺陷信息数组
   * @returns 
   */
  FlawMujian.uploadPolInfo = async (data) => {
    // ignoreDuplicates: 忽略重复数据
    let res = await FlawMujian.bulkCreate(data, {ignoreDuplicates : true});
    return res;
  }
 module.exports = {
     FlawMujian,
     initFlawMujinaData
 };